<!--=================一列列表================= -->
<div class="diy_layout_box">
	<notempty name="title">
	<h3 class="tit_bg">
		<notempty name="attr['head_link']">
			<span class="R">
				<php>
				foreach($attr['head_link'] as $vo) {
					echo '<a href="' . $vo->url . '" target="_blank">' . $vo->title . '</a> ';
				}
				</php>
			</span>
		</notempty>
		{$title}
	</h3>
	</notempty>
   	<ul class="diy_ballot">
		<php>$vote_type = ($vote['type'] == 0) ? 'radio' : 'checkbox';</php>
		<php>$vote_max  = intval($vote['type']) + 1;</php>
       	<p class="tit_ballot">{$vote['title']} (最多可投{$vote_max}项)</p>
		<volist name="opt" id="vo">
       		<li>
				<span><input id="{$vo['id']}" name="vote_opt" type="{$vote_type}" class="vote_opt_check" value="{$vo['name']}" /></span>
				{$vo['name']}
			</li>
		</volist>
    </ul>
    <p class="diy_ballot_btn">
		<input id="vote_post" class="btn_sea mr10" name="" type="button" onclick="post_vote({$vote['id']},{$vote_max})"  value="投票"/>
		<input class="btn_sea" name="" type="button" onclick="show_post({$vote['id']})" value="查看详情"/>
	</p>
</div>
<script>
	//参与投票
	function post_vote(vid, max) {
		if(max == 1) {
			var opts = $('input[name=vote_opt]').filter( '[checked]' ).val();
			var opts_ids = $('input[name=vote_opt]').filter( '[checked]' ).attr("id");
		}else {
			var opts = '';
			var opts_ids = '';
			var num = 0;
			$('input[type=checkbox]').filter( '[checked]' ).each(function(i){
				opts = opts + $(this).val()+",";
				opts_ids = opts_ids + $(this).attr("id")+",";
				num = num + 1;
			});

			if(num > max){
				$.tbox.no("您最多可投"+max+"项","提示");
				setTimeout("$.tbox.close()", 1500);
				return false;
			}
		}

		if(!opts) {
			$.tbox.no('请至少选择一个选项','提示');
			setTimeout("$.tbox.close()", 1500);
			return false;
		}

		$.post("{:U('home/Vote/postVote')}",{vote_id:vid,opts:opts,opts_ids:opts_ids},function(txt){
			if(txt){
				if( -2 == txt ){
					$.tbox.no('这个投票已经结束','提示');
					setTimeout("$.tbox.close()", 1500);
				}else if( -1 == txt ){
					$.tbox.no('你已经投过一次了!','提示');
					setTimeout("$.tbox.close()", 1500);
				}else{
					//$('.vote_opt_check').attr('disabled', true);
					$('#vote_post').val('您已投票').attr('disabled', true);
					$.tbox.yes('投票成功','提示');
					setTimeout("$.tbox.close()", 1500);
				}
			}
		});
	}

	//显示投票详情
	function show_post(vid) {
		$.tbox.popup("{:U('home/Vote/showVote')}&id="+vid,"投票详情",true);
	}
</script>